Most logging frameworks have methods that take a log level, an event ID or an exception as a separate input next to the log format and its
arguments. There is a high chance that if the log level, the event ID or the exception are passed as the arguments to the message format, it was a
mistake. This rule is going to raise in that scenario.
The rule covers the following logging frameworks:
try { }
catch (Exception ex)
{
logger.LogDebug("An exception occured {Exception} with {EventId}.", ex, eventId); // Noncompliant
}
try { }
catch (Exception ex)
{
logger.LogDebug(eventId, ex, "An exception occured.");
}
Exceptions
This rule will not raise an issue if one of the parameters mentioned above is passed twice, once as a separate argument to the invocation and once
as an argument to the message format.
try { }
catch (Exception ex)
{
logger.LogDebug(ex, "An exception occured {Exception}.", ex); // Compliant
}